package demo.spring.aop.controller;


import demo.spring.aop.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class TestController {
    @Autowired
    UserService userService;

    //http://localhost:8080/test    //前置通知，最终通知 引入代理对象@DeclareParents
    @GetMapping("/test")
    public String test() {
        log.info("执行test方法");
        userService.save();
        return "ok";
    }


    //http://localhost:8080/test2?name=mxjhaima&age=18  //参数注入测试
    @GetMapping("/test2")
    public String test2(String name, Integer age) {
        log.info("执行test2方法");
        return "ok";
    }

    //http://localhost:8080/test3   //环绕通知测试
    @GetMapping("/test3")
    public String test3() {
        log.info("执行test3方法");
        return "ok";
    }

    //http://localhost:8080/test4   //访问连接点JoinPoint
    @GetMapping("/test4")
    public String test4(String s) {
        log.info("执行test4方法");
        return "ok";
    }



    //http://localhost:8080/test5   //测试切入点表达式中bean的用法，异常通知
    @GetMapping("/test5")
    public String test5() {
        log.info("执行test5方法");
        int erro=1/0;
        return "ok";
    }
}
